@extends('shop::layouts.master')
@section('title')
    订单详情
@endsection
<style>
    .ordertab1 {
        border-top: 1px solid #e6e6e6;
        border-left: 1px solid #e6e6e6;
        font-size: 12px;
        margin-bottom: 80px
    }

    .ordertab1 td {
        border-right: 1px solid #e6e6e6;
        border-bottom: 1px solid #e6e6e6;
    }

    .orderbg {
        height: 33px;
        line-height: 33px;
        background: #e6e6e6;
        text-align: center;
        border-bottom: 1px solid #d5d5d5;
    }
</style>
@section('tab')
    <div style="padding: 20px; background-color: #F2F2F2; ">
        <div class="layui-row layui-col-space15">

            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">退款/货信息</div>
                    <div class="layui-card-body" style="overflow-y: hidden;">
                    <span style="float: left; padding-right: 50px">
                    退款/货原因：{{$arr_data['refund_reason_id']['reason']}} <br>
                    @if($arr_data['refund_reason'])
                            详细内容：{{$arr_data['refund_reason']}} <br>
                        @endif
                    申请时间：{{$arr_data['created_at']}} <br>
                    @if($arr_data['deal_at'])
                            处理时间：{{$arr_data['deal_at']}} <br>
                        @endif
                    </span>
                        @if($arr_data['picture_array'])
                            @foreach($arr_data['picture_array'] as $pic)
                                <a href="{{$pic}}" target="_blank" style="margin-right: 30px">
                                    <img src="{{$pic}}" width="80" height="80"/>
                                </a>
                            @endforeach
                        @endif

                    </div>
                </div>
            </div>

            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">商品清单</div>
                    <div class="layui-card-body" style="overflow-y: hidden;">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="ordertab1">
                            <tr class="orderbg">
                                <td height="36" colspan="2">商品</td>
                                <td height="36">规格</td>
                                <td width="150">单价 x 数量 = 总价（元）</td>
                                <td width="150">类型</td>
                                <td width="120">应退金额</td>
                            </tr>
                            @foreach($arr_data['order_goods'] as $key => $val)
                                <tr align="center">
                                    <td width="100" height="115"><p class="proimg">
                                        <img src="{{$val['goods_pic']['full_src']}}" width="80" height="80"/></p>
                                    </td>
                                    <td width="300" style="padding: 10px;line-height:20px;text-align: left;">{{$val['goods_name']}}</td>
                                    <td width="120" style="padding: 10px;line-height:20px;text-align: left;">{{$val['goods_specs']}}</td>
                                    <td>{{$val['goods_price']}} x {{$val['goods_num']}} = {{$val['goods_amount']}}</td>
                                    @if($key == 0)
                                        <td rowspan="{{count($arr_data['order_goods'])}}">
                                            @if($arr_data['apply_type'] == 1)退款
                                            @elseif($arr_data['apply_type'] == 2)退货（退款）
                                            @elseif($arr_data['apply_type'] == 3)退货退款
                                            @else<span style="color: #1890ff">未知</span>
                                            @endif
                                            @if($arr_data['apply_state'] == 1)<span style="color: red">（待处理）</span>
                                            @elseif($arr_data['apply_state'] == 2)<span style="color: red">（已同意）</span>
                                            @elseif($arr_data['apply_state'] == 3)<span style="color: red">（已拒绝）</span>
                                            @endif
                                        </td>
                                        <td rowspan="{{count($arr_data['order_goods'])}}" style="line-height:20px">
                                            <p>{{$arr_data['refund_amount']}}
                                                {{--￥{{number_format(array_sum(array_column($arr_data['order_goods'], 'refund_price')),2)}}--}}</p>
                                        </td>
                                    @endif
                                </tr>
                            @endforeach

                            <tr align="center">
                                <td colspan="9" style="padding: 20px">
                                    @if($arr_data['apply_state'] == 1 && $arr_data['apply_type'] >= 2)
                                        <a title="同意申请" class="layui-btn layui-btn-war state-btn" data-title="确认同意申请吗？"
                                           data-id="{{$arr_data['id']}}" data-type='1' href="javascript:;">同意申请
                                        </a>
                                        <a title="拒绝申请" class="layui-btn layui-btn-danger state-btn"
                                           data-title="确认拒绝申请吗？"
                                           data-id="{{$arr_data['id']}}" data-type='2' href="javascript:;">拒绝申请
                                        </a>
                                    @endif
                                    @if($arr_data['apply_state'] == 2 && $arr_data['express_id'])
                                        <a onclick="xadmin.open('查看物流','{{route("shop_logistics_tracking",["id"=>$arr_data["id"],"type"=>3])}}')"
                                           title="查看物流" class="layui-btn">查看物流
                                        </a>

                                        <a title="确认收到货，并退款" class="layui-btn layui-btn-war state-btn" data-title="确认收到货，并退款吗？"
                                           data-id="{{$arr_data['id']}}" data-type='3' href="javascript:;">确认退款
                                        </a>
                                    @endif
                                    @if($arr_data['apply_type'] != 3 && $arr_data['apply_state'] == 2)
                                        <a title="确认退款吗" class="layui-btn layui-btn-war state-btn" data-title="确认退款吗？"
                                           data-id="{{$arr_data['id']}}" data-type='3' href="javascript:;">确认退款
                                        </a>
                                    @endif
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>
            </div>

        </div>
    </div>

@endsection

@section('tab_js')
    <script>
        $(document).on('click', '.state-btn', function () {
            var that = $(this);
            var id = that.data('id');
            var type = that.data('type');
            var data = {id: id, type: type};

            layer.confirm(that.data('title'), {btn: ['确定', '取消']}, function () {
                $.ajax({
                        url: 'shop-store-order-refund-handle',
                        type: 'post',
                        dataType: "json",
                        data: data,
                        success: function (result) {
                            if (result.state === 0) {
                                layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                    location_refresh();
                                });
                            } else {
                                if(type == 3){
                                    layer.msg(result.msg+'-'+result.error, {time: 2000, icon: 5});
                                }else {
                                    layer.msg(result.msg, {time: 2000, icon: 5});
                                }
                            }
                        }
                    }
                );
            });
        });
    </script>

@endsection